package com.example.ribbon.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class HellowService {

    @Autowired
    RestTemplate restTemplate;
    //加上HystrixCommand失败会调用error方法，可在error中写失败信息
    @HystrixCommand(fallbackMethod = "error")
    public String hellow2(String name){
        /**
         * 注意 http://EurekaClient/hellow?name= 这个Eureka服务页面（http://127.0.0.1:8000）中Instances currently registered with Eureka列表中要要调用的Application的名字
         * 即eurekaclient和eurekaclient2的服务中spring.application.name的值在Eureka服务页面会显示大写这里大小写都可以
         */
         return restTemplate.getForObject("http://EurekaClient/hellow?name="+name,String.class);
    }

    public String hellow(String name){
        return name + "say hellow";
    }

    public String error(String name){
        return "参数为" + name + "，调用eureka消费端eureka-client失败";
    }
}
